package com.Android.YunBaby.weibo;

import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;

public class DownImg {
    private  FileOutputStream fos = null; 
    private  BufferedInputStream bis = null; 
    private  HttpURLConnection httpUrl = null; 
    private  URL url = null; 

    private  final int BUFFER_SIZE = 1024; 
    private  byte[]   buf   =   new   byte[BUFFER_SIZE]; 
    private  int   size   =   0; 

    public void getImg(String imgurl,String name){
    try   { 

        url = new URL(imgurl);
        httpUrl = (HttpURLConnection)url.openConnection(); 
        httpUrl.connect(); 
        bis = new BufferedInputStream(httpUrl.getInputStream()); 
        fos   =   new   FileOutputStream("/sdcard/local/"+name+".png"); 

        while   ((size   =   bis.read(buf))   !=   -1)   { 
            fos.write(buf,   0,   size); 
        } 
        fos.flush(); 

    } 
    catch   (IOException   e)   { 
    	e.printStackTrace();
    } 
    catch   (ClassCastException   e)   { 
    	e.printStackTrace();
    } 
    finally   { 
        try   { 
            fos.close(); 
            bis.close(); 
            httpUrl.disconnect(); 
        } 
        catch   (IOException   e)   { 
        	e.printStackTrace();
        } 
        catch   (NullPointerException   e)   { 
        	e.printStackTrace();
        } 
    } 
}  
}
